package com.skyolder.milkbee.service;

import com.skyolder.milkbee.domain.Elector;
import com.skyolder.milkbee.repository.ElectorRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.stereotype.Service;

import javax.inject.Inject;
import java.util.List;

/**
 * Service Implementation for managing Elector.
 */
@Service
@Transactional
public class ElectorService {

    private final Logger log = LoggerFactory.getLogger(ElectorService.class);
    
    @Inject
    private ElectorRepository electorRepository;

    /**
     * Save a elector.
     *
     * @param elector the entity to save
     * @return the persisted entity
     */
    public Elector save(Elector elector) {
        log.debug("Request to save Elector : {}", elector);
        Elector result = electorRepository.save(elector);
        return result;
    }

    /**
     *  Get all the electors.
     *  
     *  @param pageable the pagination information
     *  @return the list of entities
     */
    @Transactional(readOnly = true) 
    public Page<Elector> findAll(Pageable pageable) {
        log.debug("Request to get all Electors");
        Page<Elector> result = electorRepository.findAll(pageable);
        return result;
    }

    /**
     *  Get one elector by id.
     *
     *  @param id the id of the entity
     *  @return the entity
     */
    @Transactional(readOnly = true) 
    public Elector findOne(Long id) {
        log.debug("Request to get Elector : {}", id);
        Elector elector = electorRepository.findOne(id);
        return elector;
    }

    /**
     *  Delete the  elector by id.
     *
     *  @param id the id of the entity
     */
    public void delete(Long id) {
        log.debug("Request to delete Elector : {}", id);
        electorRepository.delete(id);
    }

	public List<Elector> findByUserIdAndQuestionnaireId(Long userId, Long questionnaireId) {
		// TODO Auto-generated method stub
		return electorRepository.findByUserIdAndQuestionnaireId(userId,questionnaireId);
	}
}
